package main

import (
	"go_gin_gorm_oceanlearn_study/controller"
	"go_gin_gorm_oceanlearn_study/middleware"

	"github.com/gin-gonic/gin"
)

func CollectRoute(r *gin.Engine) *gin.Engine {
	r.Use(middleware.CORSMiddleware()) //跨域
	r.POST("/api/auth/register", controller.Register) // 用户注册
	r.POST("/api/auth/login", controller.Login) // 用户登录
	r.GET("api/auth/info", middleware.AuthMiddleware(), controller.Info) // 获取用户信息 使用中间件保护用户信息接口

	//分组
	categoryRoutes := r.Group("/categories")
	CategoryController := controller.NewCategreController()
	categoryRoutes.POST("",CategoryController.Create)
	categoryRoutes.PUT("/:id",CategoryController.Update)
	categoryRoutes.GET("",CategoryController.Show)
	categoryRoutes.DELETE("",CategoryController.Delete)
	// categoryRoutes.PATCH("",CategoryController.Show)  //部分修改

	return r
}